package xyz.xuminghai;

import java.util.Objects;
import java.util.StringJoiner;

/**
 * 2023/2/21 9:24 星期二<br/>
 *
 * 用户bean
 * @author xuMingHai
 */
public class User {

	/**
	 * 编号
	 */
	private String id;

	/**
	 * 姓名
	 */
	private String name;

	/**
	 * 年龄
	 */
	private byte age;

	/**
	 * 性别
	 */
	private Sex sex;

	public User() {
	}

	public User(String id, String name, byte age, Sex sex) {
		this.id = id;
		this.name = name;
		this.age = age;
		this.sex = sex;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public byte getAge() {
		return age;
	}

	public void setAge(byte age) {
		this.age = age;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof User)) return false;

		User user = (User) o;

		if (age != user.age) return false;
		if (!Objects.equals(id, user.id)) return false;
		if (!Objects.equals(name, user.name)) return false;
		return sex == user.sex;
	}

	@Override
	public int hashCode() {
		int result = id != null ? id.hashCode() : 0;
		result = 31 * result + (name != null ? name.hashCode() : 0);
		result = 31 * result + (int) age;
		result = 31 * result + (sex != null ? sex.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return new StringJoiner(", ", User.class.getSimpleName() + "[", "]")
				.add("id='" + id + "'")
				.add("name='" + name + "'")
				.add("age=" + age)
				.add("sex=" + sex)
				.toString();
	}

	enum Sex {
		MALE("男"),
		FEMALE("女");

		private final String value;

		Sex(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}

		@Override
		public String toString() {
			return new StringJoiner(", ", Sex.class.getSimpleName() + "[", "]")
					.add("value='" + value + "'")
					.toString();
		}
	}

}
